import task2
import unittest
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord

class Tests(unittest.TestCase):
  def setUp(self):
    self.file1 = "gene1.txt"
    self.file2 = "../hometask-files/2-bio_toolkits/gene1.fasta"
    self.file3 = "../hometask-files/2-bio_toolkits/gene3.gb"

  def test_empty_input(self):
    self.assertEqual(task2.main([]), -1)

  def test_file_extension(self):
    self.assertEqual(task2.file_extension(self.file1), 'not_valid')
    self.assertEqual(task2.file_extension(self.file2), 'fasta')
    self.assertEqual(task2.file_extension(self.file3), 'genbank')

  def test_get_gc_content(self):
    gc = task2.get_gc_content(SeqRecord(Seq("AAACGTTT")))
    self.assertEqual(gc, str(25.0))

  def test_transcription(self):
    self.assertEqual(task2.transcription(SeqRecord(Seq("ACGT"))), "ACGU")

  def test_translation(self):
    self.assertEqual(task2.translation(SeqRecord(Seq("ACGTACGTA"))), "TYV")

  def test_multiple_align(self):
    self.assertRaises(Exception, task2.multiple_align, [SeqRecord(Seq("ACGT"))], "alignment.phy", msg="Alignment of 1 sequence have no sense\n")
    
if __name__ == '__main__':
    unittest.main()
